package com.shenzhen.horselive.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.app.Notification;
import android.os.Bundle;
import android.view.View;

import com.flqy.baselibrary.utils.L;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.adapter.NoticeAdapter;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.NoticeBean;
import com.shenzhen.horselive.databinding.ActivityNoticesBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;

import java.util.ArrayList;
import java.util.List;

public class NoticesActivity extends AppBarActivity {

    ActivityNoticesBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityNoticesBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        setTitle("平台消息");
        initViews();
        initData();

    }

    //消息
    private void initData() {
        ApiFactory.getApiService().noticesList(User.get().getMyInfo().getToken())
                .compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<NoticeBean>(this) {
                    @Override
                    protected void onNextInActive(NoticeBean noticeBean) {
                        if (noticeBean.isSuccess())
                        {
                            if (noticeBean.getData()==null||noticeBean.getData().size()==0)
                            {
                                binding.containerNoData.setVisibility(View.VISIBLE);
                            }
                            else
                            {
                                binding.containerNoData.setVisibility(View.GONE);
                                adapter.setList(noticeBean.getData());
                            }
                        }else
                        {
                            showToast(noticeBean.getErrMessage());
                        }
                    }
                });
    }
    NoticeAdapter adapter;
    private void initViews() {
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
         adapter = new NoticeAdapter(this);
        binding.recyclerview.setAdapter(adapter);

    }
}